<?php
require('functions/pageLoad.php');

if($_SERVER['REQUEST_METHOD'] == 'POST'){

// insert letting

$lettingsQuery="INSERT INTO adverts SET 
name = '".$_POST['name']."', 
type = '".$_POST['type']."', 
code = '".$_POST['code']."', 
tradesman_area = '".$_POST['tradesman_area']."',
user_area = '".$_POST['user_area']."',
visitor_area = '".$_POST['visitor_area']."'";
$lettingsResult=mysql_query( $lettingsQuery ) or die ("Error in query: $lettingsQuery . " . mysql_error());

$new_id = mysql_insert_id();

header("Location: edit_advert.php?id=".$new_id);
exit;

}

require('includes/meta.php');
require('includes/header.php');
require('includes/leftColumn.php');
?><div id="middleColumn"><div id="content">

<h2>Add new Advert</h2>
<form method="post" action="add_advert.php" style="float: left; padding-top: 10px;" id="advert_form">

<div style="float: left; width: 100%">
<div class="formInputLeft"><label for="name">Advert name:</label></div>
<div class="formInputRight"><input type="text" class="textbox" id="name" name="name" style="width: 300px;" value="" /></div>
</div>

<div style="float: left; width: 100%">
<div class="formInputLeft">Banner type:</div>
<div class="formInputRight">
<input type="radio" id="type_1" name="type" value="1" checked="checked" /><label for="type_1">Content banner (468x60)</label><br />
<input type="radio" id="type_2" name="type" value="2" /><label for="type_2">Column banner (200x200)</label>
</div>
</div>

<div style="float: left; width: 100%">
<div class="formInputLeft"><label for="tradesman_area">Tradesman banner:</label></div>
<div class="formInputRight"><input type="checkbox" id="tradesman_area" name="tradesman_area" value="1" /></div>
</div>

<div style="float: left; width: 100%">
<div class="formInputLeft"><label for="user_area">User banner:</label></div>
<div class="formInputRight"><input type="checkbox" id="user_area" name="user_area" value="1" /></div>
</div>

<div style="float: left; width: 100%">
<div class="formInputLeft"><label for="visitor_area">Visitor banner:</label></div>
<div class="formInputRight"><input type="checkbox" id="visitor_area" name="visitor_area" value="1" /></div>
</div>

<div style="float: left; width: 100%">
<div class="formInputLeft"><label for="code">Banner code:</label></div>
<div class="formInputRight"><textarea name="code" id="code" rows="7" cols="35"></textarea></div>
</div>

<div class="formInputLeft"><a onclick="document.forms['advert_form'].submit();" class="button" style="color: #ffffff;">Add Advert</a></div><div class="formInputRight" id="jsErr" style="padding-top: 10px; color: #ff0000;"></div>

</form>

</div>
</div>
</div>

<?php
require('includes/footer.php');
?>